package com.itboye.sunsun.dialog;

import java.io.Serializable;

import com.itboye.sunsunhome.R;
import com.itboye.sunsun.support.BaseDialogFragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

public class WarnDialog extends BaseDialogFragment {

	View agree;
	View refuse;
	TextView titleTv;
	TextView msgTv;
	String title;
	
	String msg;
	OnDialogSelectListener listener;
	
	LinearLayout checkBox;
	
	public   WarnDialog( ) {
		 
	}
	@Override
	public void onSaveInstanceState(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onSaveInstanceState(arg0);
		arg0.putString("title", title);
		arg0.putString("msg", msg);
		arg0.putSerializable("listener", listener);
		
	}
	public   WarnDialog(String title ,String msg,OnDialogSelectListener listener) {
		this.title=title;
		this.msg=msg;
		this.listener=listener;
	}
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return inflater.inflate(R.layout.dialog_warn, null);
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		checkBox.setSelected(true);
		if (savedInstanceState!=null) {
			title=savedInstanceState.getString("title" );
			msg=savedInstanceState.getString("msg" );
			listener=(OnDialogSelectListener) savedInstanceState.getSerializable("listener");
		}
		titleTv.setText(title);
		msgTv.setText(msg);
		
		checkBox.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				v.setSelected(!v.isSelected());
			}
		});
		
		agree.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dismiss();
				if (listener!=null) {
					try {
						listener.onDialoSelect(true,checkBox.isSelected());
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		});
		
		refuse.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dismiss();
				if (listener!=null) {
					try {
						listener.onDialoSelect(false,checkBox.isSelected());
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		});
	}
	
	public interface OnDialogSelectListener extends Serializable{
		void onDialoSelect(boolean isAgree,boolean noTip);
	}
}
